package com.shinhye.elephantsafe;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.shinhye.elephantsafe.db.dao.BlackListDao;

public class AddBlackPhoneActivity extends Activity {

	private EditText et_phone;
	private CheckBox cb_phone;
	private CheckBox cb_sms;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_addblackphone);
		
		et_phone = (EditText) findViewById(R.id.et_phone);
		cb_phone = (CheckBox) findViewById(R.id.cb_phone);
		cb_sms = (CheckBox) findViewById(R.id.cb_sms);
		
	}
	
	public void addblackphone(View v) {
		String number = et_phone.getText().toString();
		boolean b_phone = cb_phone.isChecked();
		boolean b_sms = cb_sms.isChecked();
		if(TextUtils.isEmpty(number)) {
			Toast.makeText(this, "请输入要拦截的号码！", Toast.LENGTH_SHORT).show();
			return;
		}
		
		int mode = -1;
		if(b_phone && !b_sms)
			mode = 0;
		if(!b_phone && b_sms)
			mode = 1;
		if(b_phone && b_sms)
			mode = 2;
		if(!b_phone && !b_sms) {
			Toast.makeText(this, "没有选择要拦截的操作！", Toast.LENGTH_SHORT).show();
			return;
		}
		
		Intent intent = new Intent();
		intent.putExtra("number", number);
		intent.putExtra("mode", mode);
		setResult(RESULT_OK, intent);
		
		BlackListDao dao = new BlackListDao(this);
		dao.add(number, mode);
		finish();
		
	}
}
